<?php
include_once'student.php';
include_once'admin.php';
include'data_access.php ';
$st=new database_access();
$st->connect();
$student = new student();
$submit=$_POST['registration'];
$student->name=strip_tags($_POST['student_name']);
$student->mail=strip_tags($_POST['student_mail']);
$student->phone=strip_tags($_POST['student_phone']);
$student->national=strip_tags($_POST['student_national']);
$student->country=strip_tags($_POST['student_country']);
$student->city=strip_tags($_POST['student_city']);
$student->personalnumber=strip_tags($_POST['student_personalnumber']);
$student->mankind=strip_tags($_POST['student_mankind']);
$student->faculty=strip_tags($_POST['student_faculty']);
$student->level=strip_tags($_POST['student_level']);
$student->appreciation=strip_tags($_POST['student_appreciation']);
$student->fathername=strip_tags($_POST['student_fathername']);
$student->fatherpersonalnumber=strip_tags($_POST['student_fatherpersonalnumber']);
$student->sponsername=strip_tags($_POST['student_sponsername']);
$student->sponserpersonalnumber=strip_tags($_POST['student_sponserpersonalnumber']);
$student->sponserjob=strip_tags($_POST['student_sponserjob']);
$student->date=date("y-m-d");  //when the user submit.
$admin=new admin();
    if($submit){
// connection to DB.
        $_SESSION['name']=$student->name;
    if ($admin->Checkstudent($student->personalnumber)){
         include 'login.php';
echo"<script language='javascript' type='text/javascript'>
alert('لقد قمت بتسجيل بياناتك قبلا لذا عليك تسجيل الدخول');
</script>";
      }
      else {
       $admin->add_student($student);   
       
   if ($admin->CheckAccount($student->personalnumber)){
       header('location: login.php');
      }
        else{
       $admin->AddAccount($student->personalnumber,$student->name,$student->mail,$student->date); 
        header("location: loginfirst.php?ID=$student->personalnumber");
      } 
            }
    }
 else {
        header('location: design.php');    
}
?>